class TreeNode {
	int val;
	TreeNode left;
	TreeNode right;

	TreeNode() {
	}

	TreeNode(int val) {
		this.val = val;
	}

	TreeNode(int val, TreeNode left, TreeNode right) {
		this.val = val;
		this.left = left;
		this.right = right;
	}
}

public class Solution01 {
	private boolean isFind = false;
	private boolean isRoot = true;
	private TreeNode myRoot;
	private boolean isFirst = true;

	public boolean findTarget(TreeNode root, int k) {
		if (root != null) {
			if (isRoot) {
				myRoot = root;
				isRoot = false;
			}
			dfs(myRoot, k - root.val);
			if (!isFind) {
				findTarget(root.left, k);
				findTarget(root.right, k);
			}
		}
		return isFind;
	}

	private void dfs(TreeNode root, int target) {
		if (root != null) {
			if (root.val == target && !isFirst) {
				isFind = true;
				// System.out.println(root.val);
				return;
			} else if (root.val == target && isFirst) {
				// System.out.println(root.val);
				isFirst = false;
			}
			dfs(root.left, target);
			dfs(root.right, target);
		}
	}
}
